package com.eatme.web.app.coupon.common.constant;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 商品枚举类
 */
public enum GoodsType {

    WENYU("文娱",1),
    SHENGXIAN("生鲜",2),
    JIAJU("家具",3),
    OTHERS("其他",4),
    ALL("全品类",3);

    /**
     * 商品类型描述
     */
    private String description;

    /**
     * 商品编码
     */
    private Integer code;

    GoodsType(String description, Integer code) {
        this.description = description;
        this.code = code;
    }

    public static GoodsType of(Integer code) {
        Objects.requireNonNull(code);
        return Stream.of(values())
                .findAny()
                .filter(bean-> bean.code.equals(code))
                .orElseThrow(() ->new  IllegalArgumentException(code+ " not exists!"));
    }

    public String getDescription() {
        return description;
    }

    public Integer getCode() {
        return code;
    }
}
